from turbogears.widgets import Widget, CSSLink, static


class ContainedWidget(Widget):
    def display(self, *args, **kwargs):
        container = super(ContainedWidget, self).display(*args, **kwargs)
        return container.getchildren()[0]    


class NoteWidget(ContainedWidget):
    css             = [CSSLink(static, "note.css")]
    template        = "fasttrack.widgets.templates.note"
    template_vars   = ['note', 'include_container', 'read_only']
    
    def __init__(self, note, include_container=True, read_only=False, **kwargs):
        super(NoteWidget, self).__init__(**kwargs)
        self.note = note
        self.include_container = include_container
        self.read_only = read_only


class RiskWidget(Widget):
    template        = 'fasttrack.widgets.templates.risk'
    template_vars   = ['risk', 'read_only']
    
    def __init__(self, risk, read_only=False, **kwargs):
        super(RiskWidget, self).__init__(**kwargs)
        self.risk = risk
        self.read_only = read_only


class RisksWidget(Widget):
    template        = 'fasttrack.widgets.templates.risks'
    template_vars   = ['risks', 'read_only', 'show_closed']
    
    def __init__(self, risks, read_only=False, show_closed=False, **kwargs):
        super(RisksWidget, self).__init__(**kwargs)
        self.risks = risks
        self.read_only = read_only
        self.show_closed = show_closed


class IssueWidget(Widget):
    template        = 'fasttrack.widgets.templates.issue'
    template_vars   = ['issue', 'read_only']
    
    def __init__(self, issue, read_only=False, **kwargs):
        super(IssueWidget, self).__init__(**kwargs)
        self.issue = issue
        self.read_only = read_only
        

class IssuesWidget(Widget):
    template        = 'fasttrack.widgets.templates.issues'
    template_vars   = ['issues', 'read_only', 'show_closed']

    def __init__(self, issues, read_only=False, show_closed=False, **kwargs):
        super(IssuesWidget, self).__init__(**kwargs)
        self.issues = issues
        self.read_only = read_only
        self.show_closed = show_closed


class QuestionWidget(Widget):
    template        = 'fasttrack.widgets.templates.question'
    template_vars   = ['question', 'read_only']
    
    def __init__(self, question, read_only=False, **kwargs):
        super(QuestionWidget, self).__init__(**kwargs)
        self.question = question
        self.read_only = read_only


class QuestionsWidget(Widget):
    template        = 'fasttrack.widgets.templates.questions'
    template_vars   = ['questions', 'read_only']
    
    def __init__(self, questions, read_only=False, **kwargs):
        super(QuestionsWidget, self).__init__(**kwargs)
        self.questions = questions
        self.read_only = read_only


class AnswerWidget(Widget):
    template        = 'fasttrack.widgets.templates.answer'
    template_vars   = ['answer', 'read_only']

    def __init__(self, answer, read_only=False, **kwargs):
        super(AnswerWidget, self).__init__(**kwargs)
        self.answer = answer
        self.read_only = read_only


class AnswersWidget(Widget):
    template        = 'fasttrack.widgets.templates.answers'
    template_vars   = ['answers', 'question_id', 'read_only']

    def __init__(self, answers, question_id, read_only=False, **kwargs):
        super(AnswersWidget, self).__init__(**kwargs)
        self.answers = answers
        self.read_only = read_only
        self.question_id = question_id